import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.*;

import java.util.HashSet;
import java.util.Set;

public class RedisTools {

    public static JedisCluster getRedisClient(String env) {
        JedisCluster jedisCluster = null;
        String redis_host = "xxxxxxxxx"; // 替换成Redis的集群地址
        Jedis jedis = new Jedis("");

//        JedisPoolConfig config = new JedisPoolConfig();
        GenericObjectPoolConfig<Connection> poolConfig = new GenericObjectPoolConfig<>();
        poolConfig.setMaxTotal(20);
        poolConfig.setMaxIdle(10);
        poolConfig.setMinIdle(5);

        Set<HostAndPort> jedisClusterNode = new HashSet<HostAndPort>();
        //在代码里面去写死对应环境的连接信息
        if (env.toLowerCase() != "test") {
            redis_host = "";
        }
        jedisClusterNode.add(new HostAndPort(redis_host, 6379));
        jedisCluster = new JedisCluster(jedisClusterNode, 6000, 5000, 10, null, poolConfig);

        return jedisCluster;
    }

    public static void main(String[] args) {
        JedisCluster redis_client = RedisTools.getRedisClient("test");
        System.out.println(redis_client.get("xxxx"));
        System.out.println(redis_client.hgetAll("xxxx"));
        Set query_result = (Set) redis_client.zrange("xxxxx", 0, -1);
    }
}